<template>
  <div style="padding-top:50px">
    <!-- t头部导航 -->
    <van-nav-bar class="page-nav-bar" fixed>
      <template #title>
        <van-button to="/search" class="search-btn" icon="search" type="primary" >主要按钮</van-button>
      </template>
    </van-nav-bar>
    <!-- tab栏切换 -->
    <van-tabs :sticky="true" offset-top="50px" class="home-tab" v-model="active" animated swipeable>
      <van-tab :title="obj.name" v-for="obj in channellists" :key="obj.id">
        <article-list :channel_id="obj.id"></article-list>
      </van-tab>
      <template #nav-right>
        <!-- 展位盒子 -->
        <div class="placeholder-box"></div>
        <div class="right-menu">
          <i class="toutiao toutiao-gengduo" @click="show=true"></i>
        </div>
      </template>
    </van-tabs>
    <!-- 弹框 -->
    <van-popup class="editPopup" closeable close-icon-position="top-left" v-model="show" position="bottom" :style="{ height: '90%' }" >
      <popupcontent @ongo="ongo" @deletchangeactive="active--" :channels="channellists" :active="active"></popupcontent>
    </van-popup>
  </div>
</template>

<script>
import { getUserSelfchannels } from '@/api/getverify'
import { Toast } from 'vant'
import ArticleList from './components/ArticleList.vue'
import Popupcontent from './components/Popupcontent.vue'
import { getStorage } from '@/utils/storage'
export default {
  components: { ArticleList, Popupcontent },
  data () {
    return {
      active: 0,
      show: false,
      channellists: []
    }
  },

  created () {
    this.requireuserchannel()
  },

  methods: {
    async requireuserchannel () {
      // 未登录 并且 没有本地存储有数据就用本地的
      if (!this.$store.state.user && getStorage('MY-CHANNEL')) {
        this.channellists = getStorage('MY-CHANNEL')
        return false
      }
      try {
        const res = await getUserSelfchannels()
        this.channellists = res.channels
      } catch (error) {
        Toast('获取频道失败')
      }
    },
    ongo (val) {
      this.active = val
      this.show = false
    }
  }
}
</script>

<style scoped lang='less'>
.editPopup{
  padding-top: 100px ;
}
.van-nav-bar{
  .search-btn{
    width: 555px;
    height: 64px;
    background: rgba(255, 255, 255, .2);
    border: none;
    border-radius: 32px;
  }
  /deep/.van-nav-bar__title{
    max-width: unset;
  }
  .van-icon-search{
    color: #fff;
  }

}
/deep/.home-tab{
    .van-tab{
      min-width: 200px;
      border-right: 1px solid #EDEFF3;
      height: 82px;
      .van-tab__text{
        font-size: 28px;
        color: #777;
      }
    }
    .van-tabs__wrap{
      height: 82px !important;
      border-bottom: 1px solid #EDEFF3;
    }
    .van-tab--active{
      .van-tab__text{
        font-size: 30px;
        color: #333;
      }
    }
    .van-tabs__nav--line {
      padding: 0;
    }
    .van-tabs__line{
      width: 31px;
      height: 6px;
      background-color: #3296FA;
      border-radius: 3px;
      bottom: 8px;
    }
    .right-menu {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 66px;
      height: 82px;
      background-color: #fff;
      position: fixed;
      right: 0;
      i {
        font-size: 40px;
      }
      &::before {
        content: '';
        width: 2px;
        height: 58px;
        position: absolute;
        left: 0;
        top: 12px;
        background-image: url(~@/assets/images/gradient-gray-line.png);
        background-size: 100% 100%;
      }
    }
    .placeholder-box{
      width: 66px;
      flex-shrink: 0;
    }
  }

</style>
